package com.itlong.cloud.push;

import cn.jpush.api.JPushClient;
import cn.jpush.api.common.APIConnectionException;
import cn.jpush.api.common.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.utils.words.NumberHandlerUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      极光推送。
 * <desc/>
 *
 * @createDate 2017/10/11.
 */
@Service
@RefreshScope
public class JPushClientService {

    private static final Logger LOG = LoggerFactory.getLogger(JPushClientService.class);

    //国内
    @Value("${" + PlatformConstants.J_PUSH_APP_KEY + "}")
    String appKey;
    @Value("${" + PlatformConstants.J_PUSH_MASTER_SECRET + "}")
    String masterSecret;

    //国外
    @Value("${" + PlatformConstants.J_PUSH_EN_APP_KEY + "}")
    private String appKey_en;
    @Value("${" + PlatformConstants.J_PUSH_EN_MASTER_SECRET + "}")
    private String masterSecret_en;

    private String isDev = "2";  // 1 开发环境，其他为生产环境

    /**
     * <desc>
     *     推送所有平台，所有用户，内容为 msg 的通知。
     * <desc/>
     *
     * @param  msg  推送信息
     * @param  extra
     * @return  true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean push(String msg,Map<String,String> extra){
        LOG.info("【极光推送】极光推送所有平台和用户push，推送详情:" + String.format("msg:%s;extra:",msg)+extra);
        JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
        try {
            PushResult result = null;
            result = jpushClient.sendPush(buildPushAll(msg , extra));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】:物业推送自定义刷新sip失败--"+e.getMessage());
            return false;
        }

    }

    /**
     * <desc>
     *      标签推送指令。
     *      使用场景：云对讲设备消息强提示
     * <desc/>
     *
     * @param  msg
     * @param  projectId
     * @param  userPhone
     * @param  devSip
     * @param  roomSip
     * @return  true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithTag(String msg,String projectId,String userPhone,String devSip,String roomSip){
        LOG.info("【极光推送】标签推送指令pushWithTag，推送详情:" + String.format("msg:%s;projectId:%s;userPhone:%s;devSip:%s;roomSip:%s",msg,projectId,userPhone,devSip,roomSip));
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(userPhone)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        try {
            PushResult result = null;
            result = jpushClient.sendPush(buildPushByTag(msg ,projectId,userPhone,devSip,roomSip));
            System.out.println(buildPushByTag(msg ,projectId,userPhone,devSip,roomSip));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：设备端极光强推送失败"+e);
            return false;
        }

    }

    /**
     * <desc>
     *      标签推送指令。
     *      使用场景：云对讲设备消息强提示
     * <desc/>
     *
     * @param  msg
     * @param  userPhone
     * @param  devSip
     * @param  roomSip
     * @return  true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithTag(String msg,String userPhone,String devSip,String roomSip){
        LOG.info("【极光推送】标签推送指令pushWithTag，推送详情:" + String.format("msg:%s;userPhone:%s;devSip:%s;roomSip:%s",msg,userPhone,devSip,roomSip));
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(userPhone)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        try {
            PushResult result = null;
            result = jpushClient.sendPush(buildPushByTag(msg ,userPhone,devSip,roomSip));
            System.out.println(buildPushByTag(msg ,userPhone,devSip,roomSip));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：设备端极光强推送失败"+e);
            return false;
        }

    }

    /**
     * <desc>
     *      标签推送指令。(指定项目标签推送对象)
     *      使用场景：运营管理消息推送
     * <desc/>
     *
     * @param  msg
     * @param  projectId
     * @return  true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithProjectTag(String msg,String projectId){
        LOG.info("【极光推送】标签推送指令pushWithProjectTag，推送详情:"+String.format("msg:%s;projectId:%s",msg,projectId));
        JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
        try {
            PushResult result = null;
            result = jpushClient.sendPush(buildPushByProjectTag(msg ,projectId));
            System.out.println(buildPushByProjectTag(msg ,projectId));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【项目极光推送失败】：设备端极光强推送失败"+e);
            return false;
        }

    }

    /**
     * <desc>
     *      任务指令推送。
     *      使用场景：冻结，解冻，迁入，迁出，审核通过，审核不通过
     * <desc/>
     *
     * @param projectId 项目编号
     * @param userPhone  用户手机
     * @param comands  任务集合: refreshSips,刷新sip 刷新设备 1成功刷新 2失败不需要刷新
     * @param msg
     * @return true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithTaskTO(String projectId,String userPhone,Map<String,String> comands,String msg){
        LOG.info("【极光推送】任务指令推送pushWithTaskTO，推送详情:" + String.format("projectId:%s;userPhone:%s;msg:%s;comands:",projectId,userPhone,msg)+comands);
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(userPhone)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        try {
            PushResult result = null;
            result = jpushClient.sendPush(buildExtraByTag(projectId, userPhone, comands, msg));
            System.out.println(buildExtraByTag(projectId, userPhone, comands, msg));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：有项目编号的任务指令推送失败"+e.getMessage());
            return false;
        }

    }

    /**
     * <desc>
     *      任务指令推送。
     *      使用场景：重复登录推送提示方法
     * <desc/>
     *
     * @param phoneNo  用户手机
     * @param uuid  唯一ID
     * @param msg
     * @return true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithTaskTOLogin(String phoneNo,String uuid,String msg){
        LOG.info("【极光推送】任务指令推送pushWithTaskTO，推送详情:" + String.format("phoneNo:%s;uuid:%s;msg:%s;环境:%s",phoneNo,uuid,msg,isDev));
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(phoneNo)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        try {
            PushResult result = null;
            String comandKey = "remindRepeatLogin",comandValue = "3";

            result = jpushClient.sendPush(buildExtraLoginByTag(phoneNo, uuid, msg,comandKey,comandValue));
            System.out.println(buildExtraLoginByTag(phoneNo, uuid, msg,comandKey,comandValue));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：重复登录任务指令推送失败"+e.getMessage());
            return false;
        }

    }

    /**
     * <desc>
     *      任务指令推送。
     *      使用场景：冻结，解冻，迁入，迁出，审核通过，审核不通过
     * <desc/>
     *
     * @param userPhone  用户手机
     * @param comands  任务集合: refreshSips,刷新sip 刷新设备 1成功刷新 2失败不需要刷新
     * @param msg
     * @return true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithTaskTO(String userPhone,Map<String,String> comands,String msg){
        LOG.info("【极光推送】pushWithTaskTO，推送详情:" + String.format("userPhone:%s;msg:%s;comands:",userPhone,msg)+comands);
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(userPhone)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        try {
            PushResult result = null;
            result = jpushClient.sendPush(buildExtraPhoneByTag(userPhone, comands, msg));
            System.out.println(buildExtraPhoneByTag(userPhone, comands, msg));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：推送所有平台手机用户任务指令推送失败"+e.getMessage());
            return false;
        }

    }


    /**
     * <desc>
     *      任务指令推送。
     *      使用场景：APP账单详情
     * <desc/>
     *
     * @param userPhone  用户手机
     * @param serviceType  服务类型
     * @param msg
     * @return true 成功 false 失败
     * @author Jiaqi.X
     * @createDate 2018/08/20
     */
    public boolean pushWithTaskForBillTO(String userPhone,String serviceType,String msg,String projectId,String feeId){
        LOG.info("【极光推送】pushWithTaskTO，推送详情:" + String.format("userPhone:%s;msg:%s;serviceType:%s",userPhone,msg,serviceType));
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(userPhone)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        Map<String,String> commands = new HashMap<>();
        commands.put("serviceType",serviceType);
        commands.put("projectId",projectId);
        commands.put("feeId",feeId);
        try {
            PushResult result = null;
            //推送通知、及自定消息
            jpushClient.sendPush(buildExtraNoticeBillByTag(userPhone, msg, commands));
            result = jpushClient.sendPush(buildExtraCustomBillByTag(userPhone, msg, commands));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：推送所有平台手机用户任务指令推送失败"+e.getMessage());
            return false;
        }
    }

    /**
     * <desc>
     *      任务指令推送指令—用于一卡通解冻住户。
     * <desc/>
     *
     * @param userPhone
     * @param comands  任务集合: refreshSips,刷新sip
     * @param msg
     * @return  true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithTask(String userPhone,Map<String,String> comands,String msg){
        LOG.info("【极光推送】pushWithTask，推送详情:" + String.format("userPhone:%s;msg:%s;comands:",userPhone,msg)+comands);
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(userPhone)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        try {
            PushResult result = null;
            result = jpushClient.sendPush(enableKaByTag(userPhone, comands, msg));
            System.out.println(enableKaByTag(userPhone, comands, msg));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：无项目编号的任务指令推送失败"+e);
            return false;
        }

    }

    /**
     * <desc>
     *      任务指令推送指令—用于项目的禁用启用。
     * <desc/>
     *
     * @param projectId
     * @param comands  任务集合: refreshSips,刷新sip
     * @param isChina 1是中国 2是国外
     * @param msg
     * @return  true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithProjectTask(String projectId,Map<String,String> comands,String msg,Integer isChina){
        LOG.info("【极光推送】pushWithTask，推送详情:" + String.format("projectId:%s;msg:%s;comands:",projectId,msg)+comands);
        JPushClient jpushClient =null;
        if(isChina==1){
            jpushClient = new JPushClient(masterSecret, appKey, 0);
        }else{
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 0);
        }
        try {
            PushResult result = null;
            result = jpushClient.sendPush(enableKaByProjectTag(projectId, comands, msg));
            System.out.println(enableKaByProjectTag(projectId, comands, msg));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：项目的禁用启用的任务指令推送失败" + e);
            return false;
        }

    }

    /**
     * <desc>
     *      根据别名推送消息指令。
     * <desc/>
     *
     * @param  alias 别名列表
     * @param  msg 推送消息
     * @return true 成功 false 失败
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public boolean pushWithAliases(List<String> alias, String msg) {
        LOG.info("【极光推送】pushWithAliases，推送详情:" + String.format("msg:%s;alias:",msg)+alias);
        JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
        try {
            PushResult  result = jpushClient.sendPush(buildPushObject_all_alias_alert(alias,msg));
            LOG.info("Got result - " + result);
            return result.isResultOK();
        } catch (APIConnectionException e) {
            LOG.error("Connection error. Should retry later. ", e);
            return false;
        } catch (APIRequestException e) {
            LOG.error("Error response from JPush server. Should review and fix it. ", e);
            LOG.info("HTTP Status: " + e.getStatus());
            LOG.info("Error Code: " + e.getErrorCode());
            LOG.info("Error Message: " + e.getErrorMessage());
            LOG.info("Msg ID: " + e.getMsgId());
            return false;
        }
    }

    //buildFaceVerificationByTag

    /**
     * <desc>
     *      人脸认证消息推送。
     * <desc/>
     *
     * @param  userPhone 用户手机号
     * @param  msg 消息
     * @param  comands 命令
     * @return
     * @author shengen.T
     * @createDate 2018-05-08
     */
    public boolean pushWithFaceVerificationTask(String userPhone,String msg,Map<String,String> comands){
        LOG.info("【极光推送】pushWithFaceVerificationTask，推送详情:" + String.format("userPhone:%s;msg:%s;comands:%s",userPhone,msg,comands));
        JPushClient jpushClient = null;
        if(NumberHandlerUtil.isPhoneNo(userPhone)){
            jpushClient = new JPushClient(masterSecret, appKey, 3);
        }else {
            jpushClient = new JPushClient(masterSecret_en, appKey_en, 3);
        }
        try {
            PushResult result = null;
            result = jpushClient.sendPush(buildFaceVerificationByTag(userPhone,msg,comands));
            System.out.println(buildFaceVerificationByTag(userPhone,msg,comands));
            return result.isResultOK();
        } catch (Exception e) {
            LOG.error("【极光推送失败】：人脸认证消息推送的任务指令推送失败" + e);
            return false;
        }

    }

    /**
     * <desc>
     *      构建推送对象—所有平台、所有用户、内容为 msg 的通知。
     * <desc/>
     *
     * @param  msg 推送信息
     * @param  extra
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    private PushPayload buildPushAll(String msg, Map<String,String> extra) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.all())
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(extra)
                        .build())
                .build();
    }

    /**
     * <desc>
     *     构建推送自定义指令对象（针对所有平台、指定手机用户）—用于一卡通解冻住户。
     * <desc/>
     *
     * @param  userPhone 用户手机号
     * @param  commands 如刷新sip
     * @param  msg 推送信息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public  PushPayload enableKaByTag(String userPhone,Map<String,String> commands,String msg) {
        boolean flag ="1".equals(isDev)?false:true;
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(userPhone))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(commands)
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

    /**
     * <desc>
     *     构建推送自定义指令对象（针对所有平台、指定项目）—用于一卡通解冻住户。
     * <desc/>
     *
     * @param  projectId 项目编号
     * @param  commands 如刷新sip
     * @param  msg 推送信息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public  PushPayload enableKaByProjectTag(String projectId,Map<String,String> commands,String msg) {
        boolean flag =("1".equals(isDev)?false:true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(projectId))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(commands)
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

    /**
     * <desc>
     *      构建标签推送对象（针对所有平台）—向所有平台标签为 tag 推送msg消息。
     * <desc/>
     *
     * @param msg 推送信息
     * @param tag 推送目标是标签
     * @param extra
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public PushPayload buildPushByTag(String msg,String tag,Map<String,String> extra) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag(tag))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(extra)
                        .build())
                .build();
    }


    /**
     * <desc>
     *      构建别名推送对象（针对所有平台、单个）—向所有平台别名为 alias 推送msg消息。
     * <desc/>
     *
     * @param  msg 推送消息
     * @param  alias 推送目标是别名
     * @param  extra
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    private PushPayload buildPushByAlias(String msg,String alias,Map<String,String> extra){
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.alias(alias))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(extra)
                        .build())
                .build();
    }

    /**
     * <desc>
     *     构建别名推送对象（针对所有平台，别名列表）—向所有平台别名为 userList 推送msg消息。。
     * <desc/>
     *
     * @param userList 别名列表
     * @param msg 推送消息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public static PushPayload buildPushObject_all_alias_alert(List<String> userList, String msg) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())//设置接受的平台
                .setAudience(Audience.alias(userList))//Audience设置为all，说明采用广播方式推送，所有用户都可以接收到
                .setNotification(Notification.newBuilder().setAlert(msg)
                        .addPlatformNotification(IosNotification.newBuilder().setSound("happy.caf").build())
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(false).build())//true 为IOS正式环境
                .build();
    }

    /**
     * <desc>
     *      构建标签推送对象（针对所有平台、指定项目和用户手机号）。
     *      使用场景：云对讲设备消息强提示
     * <desc/>
     *
     * @param msg  推送消息
     * @param projectId  项目编号
     * @param userPhone  用户手机号
     * @param devSip
     * @param roomSip
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public PushPayload buildPushByTag(String msg,String projectId,String userPhone, String devSip, String roomSip) {
        boolean flag =("1".equals(isDev)?false:true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(projectId, userPhone))
                        //.setNotification(Notification.newBuilder().setAlert(msg).addPlatformNotification(IosNotification.newBuilder().setSound("notes_of_the_optimistic.caf").autoBadge().addExtra("devSip", devSip).addExtra("roomSip", roomSip).addExtra("pushTime", new Date().getTime()).build()).build())
                .setNotification(Notification.newBuilder().setAlert(msg)
                                .addPlatformNotification(IosNotification.newBuilder().setSound("notes_of_the_optimistic.caf").autoBadge().addExtra("devSip", devSip).addExtra("roomSip", roomSip).addExtra("pushTime", new Date().getTime()).build())
                                .addPlatformNotification(AndroidNotification.newBuilder().setAlert(msg).addExtra("devSip", devSip).addExtra("roomSip", roomSip).addExtra("pushTime", new Date().getTime()).build())
                                .build()

                )
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

    /**
     * <desc>
     *      构建标签推送对象（针对所有平台、指定项目）。
     *      使用场景：运营管理消息推送
     * <desc/>
     *
     * @param msg  推送消息
     * @param projectId  项目编号
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public PushPayload buildPushByProjectTag(String msg,String projectId) {
        boolean flag =("1".equals(isDev)?false:true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(projectId))
                        //.setNotification(Notification.alert(msg))
                .setNotification(Notification.newBuilder().setAlert(msg)
                        .addPlatformNotification(IosNotification.newBuilder().setSound("notes_of_the_optimistic.caf").autoBadge().addExtra("projectId", projectId).build())
                        .addPlatformNotification(AndroidNotification.newBuilder().setAlert(msg).addExtra("projectId", projectId).build())
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }


    /**
     * <desc>
     *      构建自定义指令标签的对象 （针对所有平台、指定项目和用户手机号）。
     *       使用场景：冻结，解冻
     * <desc/>
     *
     * @param projectId  项目编号
     * @param userPhone  用户手机号
     * @param commands  如刷新sip
     * @param msg   推送消息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public PushPayload buildExtraByTag(String projectId, String userPhone, Map<String, String> commands, String msg) {
        boolean flag = ("1".equals(isDev) ? false : true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(projectId, userPhone))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(commands)
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

    /**
     * <desc>
     *      构建自定义指令标签的对象 （针对所有平台、指定用户手机号）。
     *      使用场景：重复登录推送提示方法
     * <desc/>
     *
     * @param phoneNo  用户手机号
     * @param uuid  唯一编号
     * @param msg   推送消息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public  PushPayload buildExtraLoginByTag(String phoneNo,String uuid,String msg,String comandKey,String comandValue) {
        boolean flag =("1".equals(isDev)?false:true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(phoneNo, uuid))
                .setNotification(Notification.newBuilder().setAlert(msg)
                                .addPlatformNotification(IosNotification.newBuilder().autoBadge().setContentAvailable(true).addExtra(comandKey, comandValue).build())
                                .addPlatformNotification(AndroidNotification.newBuilder().setAlert(msg).addExtra(comandKey, comandValue).build())
                                .build()
                )
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();

        /*boolean flag =("1".equals(isDev)?false:true);
        Map<String,String> commands = new HashMap<>();
        commands.put("remindRepeatLogin","3");
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(phoneNo,uuid))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(commands)
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();*/

    }

    /**
     * <desc>
     *      构建自定义指令标签的对象 （针对所有平台、指定用户手机号）。
     *      使用场景：v1.7 app 消息推送
     * <desc/>
     *
     * @param phoneNo  用户手机号
     * @param msg   推送消息
     * @return
     * @author Jiaqi.X
     * @createDate 2018/09/04
     */
    public  PushPayload buildExtraNoticeBillByTag(String phoneNo,String msg,Map<String,String> commands) {
        boolean flag =("1".equals(isDev)?false:true);
        //发送通知
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(phoneNo))
                .setNotification(Notification.newBuilder().setAlert(msg)
                                .addPlatformNotification(IosNotification.newBuilder().autoBadge().setContentAvailable(true).addExtras(commands).build())
                                .addPlatformNotification(AndroidNotification.newBuilder().setAlert(msg).addExtras(commands).build())
                                .build()
                )
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

    /**
     * <desc>
     *      构建自定义指令标签的对象 （针对所有平台、指定用户手机号）。
     *      使用场景：重复登录推送提示方法
     * <desc/>
     *
     * @param phoneNo  用户手机号
     * @param msg   推送消息
     * @return
     * @author Jiaqi.X
     * @createDate 2018/09/04
     */
    public  PushPayload buildExtraCustomBillByTag(String phoneNo,String msg,Map<String,String> commands) {
        boolean flag =("1".equals(isDev)?false:true);
        //发送自定义消息
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(phoneNo))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(commands)
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

    /**
     * <desc>
     *      构建自定义指令标签的对象 （针对所有平台、用户手机号）。。
     * <desc/>
     *
     * @param userPhone  用户手机号
     * @param commands  如刷新sip
     * @param msg   推送消息
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public PushPayload buildExtraPhoneByTag(String userPhone, Map<String, String> commands, String msg) {
        boolean flag = ("1".equals(isDev) ? false : true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(userPhone))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(commands)
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }


    /**
     * <desc>
     *      构建标签推送对象（针对所有平台和用户手机号）。
     *      使用场景：云对讲设备消息强提示
     * <desc/>
     *
     * @param msg  推送消息
     * @param userPhone  用户手机号
     * @param devSip
     * @param roomSip
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public PushPayload buildPushByTag(String msg,String userPhone, String devSip, String roomSip) {
        boolean flag =("1".equals(isDev)?false:true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and( userPhone))
                .setNotification(Notification.newBuilder().setAlert(msg)
                                .addPlatformNotification(IosNotification.newBuilder().setSound("notes_of_the_optimistic.mp3").autoBadge().addExtra("devSip", devSip).addExtra("roomSip", roomSip).addExtra("pushTime", new Date().getTime()).build())
                                .addPlatformNotification(AndroidNotification.newBuilder().setAlert(msg).addExtra("devSip", devSip).addExtra("roomSip", roomSip).addExtra("pushTime", new Date().getTime()).build())
                                .build()

                )
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }


    /**
     * <desc>
     *      构建标签推送对象（针对所有平台和用户手机号）。
     *      使用场景：推送账单信息
     * <desc/>
     *
     * @param msg  推送消息
     * @param userPhone  用户手机号
     * @param serviceType
     * @return
     * @author shengen.T
     * @createDate 2017/10/12
     */
    public PushPayload buildPushAccountDetailByTag(String msg,String userPhone, String serviceType) {
        boolean flag =("1".equals(isDev)?false:true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(userPhone))
                .setNotification(Notification.newBuilder().setAlert(msg)
                                .addPlatformNotification(IosNotification.newBuilder().addExtra("serviceType", serviceType).build())
                                .addPlatformNotification(AndroidNotification.newBuilder().setAlert(msg).addExtra("serviceType", serviceType).build())
                                .build()
                )
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

    /**
     * <desc>
     *      构建自定义指令标签的对象 （针对所有平台、指定用户手机号）。
     *      使用场景：人脸认证消息通知
     * <desc/>
     *
     * @param userPhone  用户手机号
     * @param msg   推送消息
     * @param commands 命令
     * @return
     * @author shengen.T
     * @createDate 2018/05/08
     */
    public  PushPayload buildFaceVerificationByTag(String userPhone,String msg,Map<String,String> commands) {
        boolean flag = ("1".equals(isDev) ? false : true);
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())
                .setAudience(Audience.tag_and(userPhone))
                .setMessage(Message.newBuilder()
                        .setMsgContent(msg)
                        .addExtras(commands)
                        .build())
                .setOptions(Options.newBuilder().setApnsProduction(flag).build())//true 为生产环境 ，false为开发环境
                .build();
    }

}